package tasks.leetcode.oj;

public class Task1 {
    public static void main(String[] args) {
        System.out.println(minSum("a123bc"));   // 输出: 6  (1+2+3)
        System.out.println(minSum("a003bc"));   // 输出: 3  (0+0+3)
        System.out.println(minSum("a01b02"));   // 输出: 3  (0+1+0+2)
        System.out.println(minSum("0"));        // 输出: 0
        System.out.println(minSum("abc"));      // 输出: 0  (无数字)
        System.out.println(minSum(""));         // 输出: 0  (空串)
        System.out.println(minSum("123"));      // 输出: 6  (1+2+3)
        System.out.println(minSum("hello9world8")); // 输出: 17 (9+8)
        System.out.println(minSum("000"));      // 输出: 0  (0+0+0)
    }

    static int minSum(String str) {
        if (str == null || str.length() == 0) {
            return 0;
        }
        int n = str.length();
        int i =0;
        int sum = 0;
        while (i < n) {
            if (Character.isDigit(str.charAt(i))) {
                sum = sum+str.charAt(i)-'0';
            }
            i++;
        }
        return sum;
    }
}
